Fix the win32 build
authorMatthias Clasen <mclasen@redhat.com>
Wed, 29 May 2019 17:31:37 +0000 (17:31 +0000)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 29 May 2019 18:04:13 +0000 (18:04 +0000)
gdk_display_get_monitor_at_point was used
in this backend.

gdk/win32/gdksurface-win32.c

index 4336dcbbc737837b4bde0e1061dd130fa9e059a2..be14e854a6342b1bb6ce706e8bb622d3930edc13 100644 (file)
@@ -3328,6 +3328,74 @@ update_fullup_indicator (GdkSurface                   *window,
   ensure_snap_indicator_surface (context, from_or_to.width, from_or_to.height, impl->surface_scale);
 }
 
+static GdkMonitor *
+get_monitor_at_point (GdkDisplay *display,
+                      int         x,
+                      int         y)
+{
+  GdkMonitor *nearest = NULL;
+  int nearest_dist = G_MAXINT;
+  int n_monitors, i;
+
+  n_monitors = gdk_display_get_n_monitors (display);
+  for (i = 0; i < n_monitors; i++)
+    {
+      GdkMonitor *monitor;
+      GdkRectangle geometry;
+      int dist_x, dist_y, dist;
+
+      monitor = gdk_display_get_monitor (display, i);
+      gdk_monitor_get_geometry (monitor, &geometry);
+
+      if (x < geometry.x)
+        dist_x = geometry.x - x;
+      else if (geometry.x + geometry.width <= x)
+        dist_x = x - (geometry.x + geometry.width) + 1;
+      else
+        dist_x = 0;
+
+      if (y < geometry.y)
+        dist_y = geometry.y - y;
+      else if (geometry.y + geometry.height <= y)
+        dist_y = y - (geometry.y + geometry.height) + 1;
+      else
+        dist_y = 0;
+
+      dist = dist_x + dist_y;
+      if (dist < nearest_dist)
+        {
+          nearest_dist = dist;
+          nearest = monitor;
+        }
+
+      if (x < geometry.x)
+        dist_x = geometry.x - x;
+      else if (geometry.x + geometry.width <= x)
+        dist_x = x - (geometry.x + geometry.width) + 1;
+      else
+        dist_x = 0;
+
+      if (y < geometry.y)
+        dist_y = geometry.y - y;
+      else if (geometry.y + geometry.height <= y)
+        dist_y = y - (geometry.y + geometry.height) + 1;
+      else
+        dist_y = 0;
+
+      dist = dist_x + dist_y;
+      if (dist < nearest_dist)
+        {
+          nearest_dist = dist;
+          nearest = monitor;
+        }
+
+      if (nearest_dist == 0)
+        break;
+    }
+
+  return nearest;
+}
+
 static void
 start_indicator (GdkSurface                   *window,
                  GdkW32DragMoveResizeContext *context,
@@ -3343,7 +3411,7 @@ start_indicator (GdkSurface                   *window,
   GdkWin32Surface *impl = GDK_WIN32_SURFACE (window);
 
   display = gdk_surface_get_display (window);
-  monitor = gdk_display_get_monitor_at_point (display, x, y);
+  monitor = get_monitor_at_point (display, x, y);
   gdk_monitor_get_workarea (monitor, &workarea);
 
   maxysize = GetSystemMetrics (SM_CYVIRTUALSCREEN) / impl->surface_scale;